<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //数组转换为字符串
        //1.toString()将数组转换为字符串
        var arr = [1, 2, 3];
        console.log(arr.toString());
        //2.join(分隔符)
        var arr1 = ['green', 'blue', 'found'];
        console.log(arr1.join()); //默认逗号
        console.log(arr1.join('-')); //'-'
        console.log(arr1.join('&')); //'&'

        //3.slice() 
        // 方法返回一个新的数组对象，这一对象是一个由 begin 和 end 决定的原数组的浅拷贝（包括 begin，不包括end）。原始数组不会被改变。
        var f1 = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']
        var f2 = f1.slice(1, 3);
        console.log(f1);
        console.log(f2);

        // 4.splice() 
        // 方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。此方法会改变原数组。
        var f3 = ["angel", "clown", "mandarin", "sturgeon"];
        var f4 = f3.splice(2, 0, "drum");
        console.log(f3);
        console.log(f4);
        // 运算后的 f3: ["angel", "clown", "drum", "mandarin", "sturgeon"]
        // 被删除的元素: [], 没有元素被删除

        var myFish = ['angel', 'clown', 'drum', 'mandarin', 'sturgeon'];
        var removed = myFish.splice(3, 1);
        console.log(myFish);
        console.log(removed);
        // 运算后的 myFish: ["angel", "clown", "drum", "sturgeon"]
        // 被删除的元素: ["mandarin"]
    </script>
</head>

<body>

</body>

</html>